package com.imooc;

public class Initial {
	public static void main(String[] args) {
		Animal animal = new Animal();
		System.out.println("初始化年龄：" + animal.age);
		Dog dog = new Dog();
		System.out.println(dog);
		dog.age = 10;
		dog.name = "lala";
		dog.eat();
		
		//继承
		Animal obj1 = new Animal();
		Animal obj2 = new Dog();
		obj1.eat();
		obj2.eat();
		//多态
		Airplay airplay = new Airplay();
		Car car = new Car();
		Boat boat = new Boat();
		airplay.func();
		car.func();
		boat.func();
		
		//类的类型转换
		if(dog instanceof Animal) {
			animal = dog; 	//向上类型转换
		} else {
			System.out.println("无法进行类型转换，转换成Dog类型");
		}
		
		if(animal instanceof Cat) {
			Cat cat = (Cat)animal;
		} else {
			System.out.println("无法进行类型转换，转换成Cat类型");
		}
		
		//4-3抽象类
		Phone phn1 = new CellPhone();
		Phone phn2 = new SmartPhone();
		phn1.call();
		phn1.message();
		phn2.call();
		phn2.message();
		
		//4-3练习
		
		//4-5接口
		IPlayGame play1 = new SmartPhone();
		IPlayGame play2 = new Psp();
		play1.playGame();
		play2.playGame();
		
		IPlayGame play3 = new IPlayGame() {

			public void playGame() {
				// TODO Auto-generated method stub
				System.out.println("使用匿名内部类的方式实现接口");
			}
			
		};
		play3.playGame();
	}

}
